package com.faiz.algorithm;

public class TreeTest {

    private static final String SEP = "->";

    public TreeNode printTree(TreeNode root, StringBuilder sb) {
        if (root == null) return null;

        TreeNode pre = printTree(root.left, sb);
        if (pre != null) {
            sb.append(pre.val).append(SEP).append(root.val).append(SEP);
        }
        TreeNode nxt = printTree(root.right, sb);
        if (nxt != null) {
            sb.append(nxt.val).append(SEP);
        }
        return root;
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(2);
        root.left = new TreeNode(1);
        root.right = new TreeNode(3);
        root.right.right = new TreeNode(4);
        TreeTest treeTest = new TreeTest();
        StringBuilder sb = new StringBuilder();
        treeTest.printTree(root, sb);
        System.out.println(sb.toString());
    }
}
